﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace Project3
{
    public class CollisionPoint
    {
        public float fdist;
        public float rdist;
        public float radius;
        public CollisionPoint(float fdist, float rdist, float radius)
        {
            this.fdist = fdist;
            this.rdist = rdist;
            this.radius = radius;
        }
    }
    public abstract class Collidable
    {
        public abstract Vector3 Position { get; set; }
        public virtual Vector3 Orientation { get { return new Vector3(0, 0, 0); } set { } }
        public virtual Vector3 Right { get { return new Vector3(0, 0, 0); } set { } }

        protected List<CollisionPoint> points;
        public void AddCollisionPoint(CollisionPoint point)
        {
            points.Add(point);
        }
        public void AddCollisionPoint(float fdist, float rdist, float radius)
        {
            AddCollisionPoint(new CollisionPoint(fdist, rdist, radius));
        }

        public Collidable()
        {
            points = new List<CollisionPoint>();
        }
        public bool CollidesWith(Collidable obj)
        {
            foreach (CollisionPoint point in points)
            {
                Vector3 pt = Position + point.fdist * Orientation + point.rdist * Right;
                foreach (CollisionPoint opoint in obj.points)
                {
                    Vector3 opt = obj.Position + opoint.fdist * obj.Orientation + opoint.rdist * obj.Right;
                    if ((pt - opt).Length() < point.radius + opoint.radius)
                        return true;
                }
            }
            return false;
        }
    }
}
